//
//  MainViewController.m
//  RoadVehicles
//
//  Created by appleLJ on 2018/2/26.
//  Copyright © 2018年 appleLJ. All rights reserved.
//

#import "MainViewController.h"
#import "RechargeViewController.h"
#import "AssistanceUnitViewController.h"
#import "MineViewController.h"
#import "PublicityViewController.h"
#import "HelpEachOtherViewController.h"
#import "IWTabBar.h"
#import "LoginViewController.h"
@interface MainViewController ()<IWTabBarDelegate>

@end

@implementation MainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    //初始化一个自定义的tabbar
    IWTabBar *tabbar = [[IWTabBar alloc] init];
    tabbar.delegate = self;
    
    //因为是只读属性,所以通过kvc的方式去赋值
    [self setValue:tabbar forKeyPath:@"tabBar"];
    
    HelpEachOtherViewController *helpEachOtherVc = [[HelpEachOtherViewController alloc] init];
    PublicityViewController *publicityVc = [[PublicityViewController alloc] init];
    RechargeViewController *rechargeVc = [[RechargeViewController alloc] init];
    AssistanceUnitViewController *assistanceUnitVc = [[AssistanceUnitViewController alloc] init];
    MineViewController *mineVc = [[MineViewController alloc] init];
    LoginViewController * loginVc = [[LoginViewController alloc] init];
    
    [self addchildViewVc:helpEachOtherVc withImagName:@"mutual_gray_icon" withSelectedImageName:@"mutual_green_icon" andTitle:@"互助计划"];
    [self addchildViewVc:publicityVc withImagName:@"publicity_gray_icon" withSelectedImageName:@"publicity_green_icon" andTitle:@"公示"];
    [self addchildViewVc:rechargeVc withImagName:@"recharge_gray_icon" withSelectedImageName:@"recharge_green_icon" andTitle:@"计划充值"];
    [self addchildViewVc:assistanceUnitVc withImagName:@"assist_gray_icon" withSelectedImageName:@"assist_green_icon" andTitle:@"协助单位"];
    
//    if ([[UserModel sharedInstanced].userID isEqualToString:@""]) {
////        [self addchildViewVc:loginVc withImagName:@"" withSelectedImageName:@"" andTitle:@"我的"];
//        [self addchildViewVc:mineVc withImagName:@"my_gray_icon" withSelectedImageName:@"my_green_icon" andTitle:@"我的"];
//        [self.navigationController presentViewController:loginVc animated:YES completion:nil];
//    }else{
        [self addchildViewVc:mineVc withImagName:@"my_gray_icon" withSelectedImageName:@"my_green_icon" andTitle:@"我的"];
//    }
}

//添加子控制器方法
- (void)addchildViewVc:(UIViewController *)vc withImagName:(NSString *)imgName withSelectedImageName:(NSString *)selectedImgName andTitle:(NSString *)titile{
    
    //设置标题
    vc.title = titile;
    //vc.navigationController.title = titile;
    //设置选中状态item背景颜色
    [vc.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName:getColor(greenBGColor),NSFontAttributeName:DEF_FontSize_12} forState:UIControlStateSelected];
    
    UIImage * unSelectImg = [UIImage imageNamed:imgName];
    unSelectImg = [unSelectImg  imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage * selectImge = [UIImage imageNamed:selectedImgName];
    selectImge = [selectImge imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置图片
    vc.tabBarItem.image = unSelectImg;
    //设置选中图片
    vc.tabBarItem.selectedImage = selectImge;
    
    //添加子控制器
    UINavigationController *navVc = [[UINavigationController alloc] initWithRootViewController:vc];
    [[UINavigationBar appearance] setTranslucent:NO];
    [self addChildViewController:navVc];
}

#pragma mark -- IWTabBarDelegate
- (void)tabBar:(IWTabBar *)tabBar didSelectPlusButton:(UIButton *)button{
    NSLog(@"aaaa");
}

@end
